Repository navigation
Add a run journal, progress modes and metrics for long runs - #79
Merged
Merged
Conversation
A publish run takes days, and when one finished short the only record of what happened was whatever scrolled past on stderr. Now every long command writes one JSON object per event to a journal file, so the two questions worth asking afterwards, which shards failed and when the rate dropped, are a jq filter away. One RunEvent schema covers the shard pipelines and the streaming commands, so a single query works across all of them. RunReporter fans each event out to the journal, to stderr in text or JSON, and to a Prometheus registry. A nil reporter is a working no-op, so library callers that never set one keep the stderr narration they have always had. Three new global flags: --progress text|json|none, which defaults to text on a terminal and json anywhere else so a supervised run logs machine readable lines without anyone remembering a flag, --journal for where the events go, and --metrics-addr to serve /metrics for the length of the run. The address is bound at startup, so a busy port fails the command there rather than an hour in. markdown export and markdown refetch emit start, per-shard, tick and end events with an inflight gauge, and default their journal to run.jsonl beside the ledger. download, export, host enrich and crawl seed report through StreamProgress, which counts items and phases on the same schedule and in the same shape. The ticker reads the run stats through an atomic.Pointer snapshot, so it never takes the committer's lock, and it recomputes rate and ETA from its own clock rather than the stats, which only advance on a commit and so say nothing when a run has stalled. The Prometheus registry is hand rolled. client_golang would do more of it, but it is a large dependency for twelve metrics in a binary whose selling point is that it has none, and the text exposition format is a dozen lines of printing. RSS moves to build-tagged files: /proc/self/status on Linux, ps on macOS, 0 elsewhere. It was Linux only, which meant it always read 0 on the machine most of this gets developed on. Also fix an export bug found while smoke testing: CDXStream wraps the callback's error with the page it came from, so the stop sentinel was never recognised and a successful `export -n 3` exited 1. Refs #46
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #46.
A publish run takes days, and when one finished short the only record of what happened was whatever scrolled past on stderr. Now every long command writes one JSON object per event to a journal file, so the two questions worth asking afterwards, which shards failed and when the rate dropped, are a jq filter away.
What is in it
One
RunEventschema covers the shard pipelines and the streaming commands, so a single query works across all of them.RunReporterfans each event out to three sinks: the journal on disk, stderr in text or JSON, and a Prometheus registry. A nil reporter is a working no-op, so library callers that never set one keep the stderr narration they have always had.Three new global flags:
--progresstext,json, ornone--journalrun.jsonlbeside the ledger--metrics-addr/metricsonThe
--progressdefault is the useful one: run it in a terminal and you get human lines, redirect it into a log file or run it under a supervisor and you get JSON, without anybody having to remember a flag. The metrics address is bound at startup, so a busy port fails the command there rather than an hour in.markdown exportandmarkdown refetchemit start, per-shard, tick and end events with an inflight gauge, and default their journal torun.jsonlbeside the ledger so a resumed run's events land next to the record of what it resumed from.download,export,host enrichandcrawl seedreport throughStreamProgress, which counts items and phases on the same schedule and in the same shape. Those four reported nothing at all before.Decisions worth flagging
The ticker reads the run stats through an
atomic.Pointersnapshot, so it never takes the committer's lock. It recomputes rate and ETA from its own clock rather than from the stats, which only advance on a commit and so say nothing at exactly the moment you need them, when a run has stalled.fetch_failedis a separate field fromfailed. A refetch shard that hit a thousand dead hosts still succeeded, and folding the two together would make a healthy run look broken.The Prometheus registry is hand rolled. client_golang would do more of it, but it is a large dependency for twelve metrics in a binary whose selling point is that it has none, and the text exposition format is a dozen lines of printing.
RSS moves to build-tagged files:
/proc/self/statuson Linux,pson macOS, 0 elsewhere. It was Linux only, which meant it always read 0 on the machine most of this gets developed on.Also fixed
Smoke testing turned up an unrelated export bug.
CDXStreamwraps the callback's error with the page it came from, so the stop sentinel was compared against a wrapped error and never matched, and a perfectly successfulccrawl export 'example.com/*' -n 3exited 1. It useserrors.Isnow.Done when
run.jsonlanswers which shards failed and when the rate droppedVerification
Real runs against Common Crawl on macOS, not just unit tests.
ccrawl export 'example.com/*' -n 3 --journal run.jsonl --progress json:Exit 0, and
rss_bytesis 45 MB rather than the 0 it read before.ccrawl download wet -n 4 -j 1 --metrics-addr 127.0.0.1:19091, scraped mid-run:The matching tick carried an ETA:
go build ./...,go vet ./...,gofmt -l .andgo test ./...are all clean, andscripts/docs-drift.shpasses with the three new flags documented.Docs
New reference page at
/reference/run-journal/with the full event schema, the metric table, and the queries worth keeping. The three flags are in the global flags table.